/**
 * 
 * showList.js
 * 展示列表
 * 
 * @author: 么苋木偶
 * @time: 2017/3/14 15:22
 * 
 * */

var buyShow;//买家端展示

$(function(){
	$.loadmore.get(getShopTouchData,{scroll:true});
})


/*touch加载更多*/
function getShopTouchData(config){
	var pageNum = $('#pageNum').val();
	var tabStatus = $('#tabStatus').val();
	/*config.isAjax = true;*/
	$.ajax({
		type : "GET", 
		dataType : "html",
		url : "/eshop/backeshopinfoListMore.htm",
		data : {
			'pageNo' : pageNum,
			'status':tabStatus
		},
		success: function(response){
			var response = response.trim();
			if(Boolean(response)){
				pageNum ++;
				$('#pageNum').val(pageNum);
				$(".backShopInfoList").append(response);
			}else{
				$(".clickmore").html('没有更多列表了');
			}
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	});
}


$('.touchBtn').on('click',function(){
	var beizhu = $(this).parent().find('.beizhu').html();
	var status = $(this).attr("status");//0：有意出售，1：无意出售 
	var eshopTouchId = $(this).attr("eshopTouchId");
	if(status == '0'){
		status = 1;
		$(this).html('无意出售');
		$(this).addClass('unConnect');
		$(this).attr('status',status);
	}else{
		status = 0;
		$(this).html('有意出售');
		$(this).removeClass('unConnect');
		$(this).attr('status',status);
	}
	$.ajax({
		type : "GET", 
		dataType : "json",
		url : "/eshop/modifyEshopTouchStatus.json",
		data : {
			'status':status,
			'remark':beizhu,
			'eshopTouchId':eshopTouchId
		},
		success: function(response){
		
		},
	})
})

$('.btnJump').on('click',function(){
	var beizhu = $(this).parent().parent().find('.beizhu').html();
	var eshopTouchId = $(this).attr("eshopTouchId");
	$.ajax({
		type : "GET", 
		dataType : "json",
		url : "/eshop/modifyEshopTouchStatus.json",
		data : {
			'eshopTouchId':eshopTouchId,
			'remark':beizhu
		},
		success: function(response){
			if(response['code'] == '200'){
				alert('提交成功');
			}
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	})
})
/*secrchInfo*/
$('.secrchInfo').on('click',function(){
	var key = $(this).prev().val();
	$.ajax({
		type : "GET", 
		dataType : "html",
		url : "/eshop/eshopTouchListMore.htm",
		data : {
			'keyWord':key
		},
		success: function(data){
			$('.backShopInfoList').html(data);
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	})
})
/*tabStatus*/
var tabStatus = $('#tabStatus').val();//1:无意出售；0：有意出售
function initTabStatus(status){
	if(status == '0'){
		$('.tsLeft').addClass('tsChecked').siblings().removeClass('tsChecked');
	}else{
		$('.tsRight').addClass('tsChecked').siblings().removeClass('tsChecked');
	}
}
initTabStatus(tabStatus);
$('.tsLeft').on('click',function(){
	$('.tsLeft').addClass('tsChecked').siblings().removeClass('tsChecked');
	$.ajax({
		type : "GET", 
		dataType : "html",
		url : "/eshop/eshopTouchListMore.htm",
		data : {
			'status':0
		},
		success: function(data){
			$('.backShopInfoList').html(data);
			$('.touchBtn').on('click',function(){
				var beizhu = $(this).parent().find('.beizhu').html();
				var status = $(this).attr("status");//0：有意出售，1：无意出售 
				var eshopTouchId = $(this).attr("eshopTouchId");
				if(status == '0'){
					status = 1;
					$(this).html('无意出售');
					$(this).addClass('unConnect');
					$(this).attr('status',status);
				}else{
					status = 0;
					$(this).html('有意出售');
					$(this).removeClass('unConnect');
					$(this).attr('status',status);
				}
				$.ajax({
					type : "GET", 
					dataType : "json",
					url : "/eshop/modifyEshopTouchStatus.json",
					data : {
						'status':status,
						'remark':beizhu,
						'eshopTouchId':eshopTouchId
					},
					success: function(response){
					
					},
				})
			})
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	})
})
$('.tsRight').on('click',function(){
	$('.tsRight').addClass('tsChecked').siblings().removeClass('tsChecked');
	$.ajax({
		type : "GET", 
		dataType : "html",
		url : "/eshop/eshopTouchListMore.htm",
		data : {
			'status':1
		},
		success: function(data){
			$('.backShopInfoList').html(data);
			$('.touchBtn').on('click',function(){
				var beizhu = $(this).parent().find('.beizhu').html();
				var status = $(this).attr("status");//0：有意出售，1：无意出售 
				var eshopTouchId = $(this).attr("eshopTouchId");
				if(status == '0'){
					status = 1;
					$(this).html('无意出售');
					$(this).addClass('unConnect');
					$(this).attr('status',status);
				}else{
					status = 0;
					$(this).html('有意出售');
					$(this).removeClass('unConnect');
					$(this).attr('status',status);
				}
				$.ajax({
					type : "GET", 
					dataType : "json",
					url : "/eshop/modifyEshopTouchStatus.json",
					data : {
						'status':status,
						'remark':beizhu,
						'eshopTouchId':eshopTouchId
					},
					success: function(response){
					
					},
				})
			})
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	})
	$('#tabStatus').val(status);
})
$('.addShop').on('click',function(){
	$('.addWrap').show();
})
$('.addBtnCancel').on('click',function(){
	$('.addWrap').hide();
})
$('.addBtnSubmit').on('click',function(){
	var eshopName = $('.shopNameInput').val();
	$.ajax({
		type : "POST", 
		dataType : "json",
		url : "/eshop/addEshopTouchAction.json",
		data : {
			'eshopName':eshopName
		},
		success: function(data){
			if(data['code'] == '200'){
				window.location.href="/eshop/eshopTouchList.htm?status=0";
			}else if(data['code'] == '-200'){
				alert("操作失败请重试");
			}else if(data['code'] == '-300'){
				alert("请填写店铺名");
			}
		},
		error: function(xhr, type){
			/*console.log('Ajax error!');*/
		}
	})
})
